﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: LogLikelihoodRatioTest.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-09-06 11:39 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using BOL.Maths.Distributions;

namespace BOL.Maths.Statistics.HypothesisTest
{
    public sealed class LogLikelihoodRatioTest : TestBase
    {
        #region Private variables

        private readonly double _ll1;

        #endregion

        #region Public properties

        public override double TestStatistic { get { return -2 * (NullValue - _ll1); } }

        #endregion

        #region Constructor

        public LogLikelihoodRatioTest(double alpha, double ll0, double ll1, int df)
            : base(TestType.Upper, alpha, ll0)
        {
            Alpha = alpha;
            _ll1 = ll1;
            Distribution = new ChiSquareDistribution(df);
        }

        #endregion

        #region Protected methods

        protected override double PointEstimate()
        {
            throw new Exception("Point estimate is undefined for log-likelihood ratio test.");
        }

        protected override double PointEstimateStandardError()
        {
            throw new Exception("Point estimate standard error is undefined for log-likelihood ratio test.");
        }

        #endregion

        #region Object overriden

        public override string ToString()
        {
            return String.Format("LogLikelihood Test (D = {0:G4}, p-value = {1:G3}): {2}", TestStatistic, PValue, (IsSignificant) ? "Reject H0" : "Accept H0");
        }

        #endregion
    }
}
